﻿using UnityEngine;
using System.Collections;

public class SelectShip2 : MonoBehaviour
{
    public moveLift liftGO;

    private int index = 0;
    private TKSwipeDirection swipeDir;
    public Rect SwipeTooltipLeft, SwipeTooltipRight, TapTooltip;
    // public Texture2D SwipeTooltipLeftTexture, SwipeTooltipRightTexture, TapTooltipTexture;
    public string[] shipText;

    string regsText;//Average Joe
    string goldyText;//Cash Money Records yo!!
    string spartaText;//Sparta!!!
    string b2Text;//Sneak and Surprise

    public string[] shipNames;
    public Transform[] showShips;
    private float idleTimer = 0f;
    private bool showTips = true;
    public float toolTipTimeout = 10f;
    private bool startOnlytip = false;
    public float blinkRate = 1.5f;
    private float t = 0, y = 0;
    private float scroll;
    [HideInInspector]
    public string infotext;
    private int damageBoost, healthBoost, fireRate, evasion, armor;

    // Use this for initialization

    public Texture2D infoTexture;
    public GUIStyle anotherGodDamGUIStyleSoICanBeRemindedToUseNGUI;
    public float infoBoxW = 0, infoBoxH = 0, infoBoxtW = 0, infoBoxtH = 0;

    

    public void swipeDetection()
    {
        //Swipe Detection
        var swipe = new TKSwipeRecognizer(TKSwipeDirection.Horizontal);
        swipe.gestureRecognizedEvent += (r) =>
        {
            swipeDir = r.completedSwipeDirection;
            idleTimer = -toolTipTimeout / 2;
            startOnlytip = true;
        };
        TouchKit.addGestureRecognizer(swipe);
    }
    IEnumerator blinkTips()
    {
        if (StartGame.gameStart)
        {
            showTips = false;
            yield break;
        }
        showTips = !showTips;
        yield return new WaitForSeconds(blinkRate);
        StartCoroutine(blinkTips());

    }
    void Start()
    {
        StartCoroutine(blinkTips());
        idleTimer = 0;
        shipNames = new string[4];
        swipeDetection();

        regsText = "U.S. Jet Fighter";
        goldyText = "Gold Digger";
        spartaText = "Sparta";
        b2Text = "B2 Bomber";

        shipNames[0] = spartaText;
        shipNames[1] = regsText;
        shipNames[2] = b2Text;
        shipNames[3] = goldyText;
        damageBoost = Random.Range(0, 11);
        healthBoost = Random.Range(0, 11);
        fireRate = Random.Range(0, 11);
        armor = Random.Range(0, 2);
        evasion = Random.Range(0, 6);


        shipText = new string[4];

        shipText[0] = "\nShield Boost: 10 \nResidential Boost: 10\nAttack Boost: 1";
        shipText[1] = "\nDamage Boost: " + damageBoost + "/10 \nHealth Boost: " + healthBoost + "/10 \nFire Rate: " + fireRate + "\nEvasion: " + evasion + "\nArmor: " + armor;
        shipText[2] = "\nDamage Boost: 10 \nEvasion: 20";
        shipText[3] = "\nInitial Currency: 400 \nCurrency Per Drop: +5";

        GameObject theLift = GameObject.Find("lift");
        liftGO = theLift.GetComponent<moveLift>();
        showShips[0].gameObject.SetActive(true);
    }
    void Update()
    {
        shipText[1] = "\nDamage Boost: " + damageBoost + "/10 \nHealth Boost: " + healthBoost + "/10 \nFire Rate: " + fireRate + "/10 \nEvasion: " + evasion + "/5 \nArmor: " + armor + "/1";
        idleTimer += Time.deltaTime;

        if (swipeDir == TKSwipeDirection.Right)
        {
            damageBoost = Random.Range(0, 11);
            healthBoost = Random.Range(0, 11);
            fireRate = Random.Range(0, 11);
            armor = Random.Range(0, 2);
            evasion = Random.Range(0, 6);

            showShips[index].gameObject.SetActive(false);
            if (index + 1 < showShips.Length)
            {
                index++;
            }

            else
                index = 0;
            showShips[index].gameObject.SetActive(true);
            swipeDir = TKSwipeDirection.All;
        }
        if (swipeDir == TKSwipeDirection.Left)
        {
            damageBoost = Random.Range(0, 11);
            healthBoost = Random.Range(0, 11);
            fireRate = Random.Range(0, 11);
            armor = Random.Range(0, 2);
            evasion = Random.Range(0, 6);

            showShips[index].gameObject.SetActive(false);
            if (index > 0)
            {
                index--;
            }
            else
                index = showShips.Length - 1;
            showShips[index].gameObject.SetActive(true);
            swipeDir = TKSwipeDirection.All;
        }

        if (PlayerPrefs.GetString("PlayerShip") == "Regs")
        {
//            PlayerPrefs.SetInt("HealthBoost", healthBoost);
//            PlayerPrefs.SetInt("DamageBoost", damageBoost);
//            PlayerPrefs.SetInt("FireRate", fireRate);
//            PlayerPrefs.SetInt("Armor", armor);
//            PlayerPrefs.SetInt("Evasion", evasion);
        }

    }
    void OnGUI()
    {
        Rect nextShipBox = new Rect(Screen.width / 2 - 10, Screen.height / 2 - 80, 150, 50);
        Rect prevShipBox = new Rect(Screen.width / 2 - 200, Screen.height / 2 - 80, 150, 50);
        Rect infoBox = new Rect(Screen.width / 2, Screen.height / 20, Screen.width / infoBoxW, Screen.height / infoBoxH);
        Rect infoBoxt = new Rect(Screen.width / 2, Screen.height / 20, Screen.width / infoBoxtW, Screen.height / infoBoxtH);



        GUIStyle stylin = new GUIStyle(GUI.skin.GetStyle("Button"));
        stylin.normal = anotherGodDamGUIStyleSoICanBeRemindedToUseNGUI.normal;
        stylin.font = anotherGodDamGUIStyleSoICanBeRemindedToUseNGUI.font;
        stylin.fontSize = anotherGodDamGUIStyleSoICanBeRemindedToUseNGUI.fontSize;
        t += Time.deltaTime / 7f;
        scroll = Mathf.Lerp(0, infoBox.y, t);
        //float scroll = Mathf.Lerp(infoBox.y, 0, t);
        infotext = shipNames[index] + "\n" + shipText[index];
        if (StartGame.gameStart)
        {
            y += Time.deltaTime / 3f;
            t = 0;
            scroll = Mathf.Lerp(infoBox.y, -infoBox.height, y);
            //  infotext = "Pick difficulty";
        }
        else if (StartGame.selectLevels)
        {

            infoBox = new Rect(Screen.width / 2, Screen.height / 10f, Screen.width, Screen.height / 5f);
        
            scroll = Mathf.Lerp(-infoBox.height, 0, t);
            infotext = "Pick a difficulty";
        }

      //GUI.Label(new Rect(infoBoxt.x - infoBoxt.width / 2, scroll, infoBoxt.width, infoBoxt.height), infotext, stylin);
      //  GUI.DrawTexture(new Rect(infoBox.x - infoBox.width / 2, scroll, infoBox.width, infoBox.height), infoTexture);
    }
}
